/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:video_player/video_player.dart';

import 'full_screen_video_page.dart';

class FullScreenPlayUtils {
  static bool isFullScreen = false;

  static void enterFullScreen(
      BuildContext context, VideoPlayerController videoController) {
    if (isFullScreen) {
      return;
    }
    try {
      isFullScreen = true;
      SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
      Navigator.push(
          context,
          PageRouteBuilder(
            pageBuilder: (_, __, ___) =>
                FullScreenVideoPage(videoController: videoController),
            transitionsBuilder:
                (context, animation, secondaryAnimation, child) {
              return FadeTransition(
                opacity: animation,
                child: child,
              );
            },
            transitionDuration: const Duration(milliseconds: 300),
            reverseTransitionDuration: const Duration(milliseconds: 300),
          ));
    } catch (e) {
      if (kDebugMode) {
        print('enterFullScreen err: ${e.toString()}');
      }
    }
  }

  static void exitFullScreen(BuildContext context) {
    if (!isFullScreen) {
      return;
    }
    isFullScreen = false;
    SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
    Navigator.pop(context);
  }
}
